import { createI18n } from 'vue-i18n'
import zhCN from '../locales/zh-CN'
import enUS from '../locales/en-US'
import jaJP from '../locales/ja-JP'

// 获取浏览器语言设置
const getBrowserLanguage = () => {
  const language = navigator.language
  if (language.includes('zh')) return 'zh-CN'
  if (language.includes('ja')) return 'ja-JP'
  return 'en-US'
}

// 获取本地存储的语言设置或使用浏览器语言
const getDefaultLanguage = () => {
  return localStorage.getItem('language') || getBrowserLanguage()
}

const i18n = createI18n({
  legacy: false, // 使用组合式API
  locale: getDefaultLanguage(),
  fallbackLocale: 'en-US', // 设置回退语言为英语
  messages: {
    'zh-CN': zhCN,
    'en-US': enUS,
    'ja-JP': jaJP
  }
})

export default i18n 